package com.example.chessbattleplatform.Pojo.Result;

import com.example.chessbattleplatform.Pojo.Exception.WebSocketCode;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class websocketResult<T> {
    // 状态码
    private WebSocketCode status;
    // 提示
    private String message;
    //提示类别
    private String TipCategory;
    //内容
    private T data;

    // 静态方法便于快速创建成功和失败的响应
    //  成功 请求成功代码
    public static <T> websocketResult<T> success(T data) {
        return success("操作成功", data);
    }

    // 成功 请求成功代码 并 添加成功信息
    public static <T> websocketResult<T> success(String Message, T data) {
        websocketResult<T> websocketResult = new websocketResult<>();
        websocketResult.setData(data);
        websocketResult.setStatus(WebSocketCode.SUCCESS_CODE);
        websocketResult.setMessage(Message);
        return websocketResult;
    }

    // 缺少参数
    public static websocketResult<Object>  missingParameter(String message){
        websocketResult<Object> websocketResult = new websocketResult<>();
        websocketResult.setStatus(WebSocketCode.PARAMETER_VALIDATION_FAILED);
        websocketResult.setMessage(message);
        return websocketResult;
    }

    // 失败 缺少或无效的 API 密钥
    public static websocketResult<Object>  unauthorized(String message){
        websocketResult<Object> websocketResult = new websocketResult<>();
        websocketResult.setStatus(WebSocketCode.PERMISSION_DENIED);
        websocketResult.setMessage(message);
        return websocketResult;
    }
    //未知 未找到指定的资源
    public static websocketResult<Object>  uncertain(String message){
        websocketResult<Object> websocketResult = new websocketResult<>();
        websocketResult.setStatus(WebSocketCode.UNKNOWN_ERROR);
        websocketResult.setMessage(message);
        return websocketResult;
    }
    // 错误 服务器内部错误
    public static  websocketResult<Object>  error(String message){
        websocketResult<Object> websocketResult = new websocketResult<>();
        websocketResult.setStatus(WebSocketCode.ERROR_CODE);
        websocketResult.setMessage(message);
        return websocketResult;
    }
}
